$('.city-page').livequery(function() {
	cityMap();
});
$('.route-page').livequery(function() {
	routeMap.init();
});

$('.city-page, .route-page, .fo-page').livequery(function() {
	accessflag = true;
	$('#fast-order').submit(function() {
		var objForm = $(this);
			if(!accessflag || !objForm.fullValidate(false)) return false;
			if($('#Order_city_from_string').val() == $('#Order_city_to_string').val()) {
				$('#Order_city_from_string, #Order_city_to_string').addClass('error-field');
				return false;
			}
			accessflag = false;
			$.ajax({
				dataType: 'json',
				url: W_AJAX + 'order/fast-order',
				type : 'POST',
				data: {
					city_from: $('#Order_city_from_string').val(),
					city_to: $('#Order_city_to_string').val(),
					phone: $('#Order_one_phone').val(),
					description: $('#Order_description').val()
				},
				success: function(data) {
					console.log(data);
					if(data.result == 'OK') {
						$('#Order_city_from_string, #Order_city_to_string, #Order_one_phone, #Order_description').val('');
						alert('Заказ отправлен');
					}
					else {
						if(data.city_from == 'FAIL') $('#Order_city_from_string').addClass('error-field');
						if(data.city_to == 'FAIL') $('#Order_city_to_string').addClass('error-field');
						if(data.phone == 'FAIL') $('#Order_one_phone').addClass('error-field');
						if(data.description == 'FAIL') $('#Order_description').addClass('error-field');
					}
					accessflag = true;
				}
			});
			return false;
	});
	$("body").livequery(function(){
		$(function(){
			$("input, textarea").hideErrors();
		});
	});
});

$('._direction').livequery(function() {	
	$(".fo-link, #fo-map area").bind('mouseover mouseout', function(e) {
		var idFO = $(this).attr('fo-id');
		if(e.type == 'mouseover') {
			$('.fo-link').each(function() {
				if($(this).attr('fo-id') == idFO) $(this).addClass('choosed');
			});
			$('#fo-map-pic img').each(function() {
				if($(this).attr('src') == '/content/images/fo-map-' + idFO + '.png') $(this).show();
			});
		}
		else {
			$('.fo-link').removeClass('choosed');
			$('#fo-map-pic img').each(function() {
				if($(this).index() != 0) $(this).hide();
			});
		}
	});
	$('#fo-map area').bind('mouseover', function() {
		console.log($(this).attr('fo-id'));
	});
});
